// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        blackBg:{
            default:null,
            type:cc.Node
        },

        coinsRankNode:{
            default:null,
            type:cc.Node
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },

    // update (dt) {},

    showWinRank:function () {
        cc.gg.tdUtil.doSendTdPageStart("RankList")
        this.openRank(this.coinsRankNode,function (node) {
            this.scheduleOnce(function () {
                let coinsWin = node.getComponent("CoinsWin")
                coinsWin.initCoinsWin(this)
            }.bind(this),0)
        }.bind(this))
    },

    openRank:function (node,cb) {
        this.blackBg.active = true
        let height = node.height
        node.active = true
        let oriHeight = cc.winSize.height/2 + height/2
        cc.log("初始高度：",oriHeight)
        node.y = oriHeight
        let moveTo = cc.moveTo(0.2,0,0)
        let callfunc = cc.callFunc(function () {
            if(cb) cb(node)
        },this)
        let seq = cc.sequence(moveTo,callfunc)
        node.runAction(seq)
    },

    closeRank:function (node) {
        cc.gg.tdUtil.doSendTdPageEnd("RankList")
        this.blackBg.active = false
        let height = node.height
        node.position = cc.v2(0,0)
        let moveBy = cc.moveTo(0.2,0,-cc.winSize.height/2 - height/2)
        let callfunc = cc.callFunc(function () {
            node.active = false
        },this)
        let seq = cc.sequence(moveBy,callfunc)
        node.runAction(seq)
    }
});
